package com.wenlin.myproduction.binder;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.RecyclerView;

import com.wenlin.myproduction.R;
import com.wenlin.myproduction.bean.GamePlayer;
import com.wenlin.myproduction.util.UI;

import me.drakeet.multitype.ItemViewBinder;

/**
 * @author 文琳
 * @Email 377979485@qq.com
 * @desc
 * @time 2022-09-03 星期六 13:10
 */
public class GamePlayerBinder extends ItemViewBinder<GamePlayer, GamePlayerBinder.GamePlayerHolder> {

    @NonNull
    @Override
    protected GamePlayerHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        return new GamePlayerHolder(inflater.inflate(R.layout.item_game_player, parent, false));
    }

    @Override
    protected void onBindViewHolder(@NonNull GamePlayerHolder holder, @NonNull GamePlayer item) {
        UI.setText(holder.tvTeam, item.getParty());
        UI.setText(holder.tvScore, item.getScore() + "分");
        UI.setText(holder.tvLevel, item.getQuality());
        UI.setText(holder.tvDesc1, item.getPro());
        UI.setText(holder.tvDesc2, item.getPro2());
        UI.setText(holder.tvPosition, item.getPosition());
        UI.setText(holder.tvName, item.getName());
        UI.setText(holder.tvYear, item.getYear());
        boolean isSSR = false;
        if (item.getQuality().equals("SSR")) {
            isSSR = true;
        }
        UI.setBackgroundResource(holder.cl, isSSR ? R.drawable.btn_orange_rect : R.drawable.btn_purple_rect);
        UI.setTextColor(holder.tvLevel, isSSR ? R.color.myOrange : R.color.myPurple);
    }

    static class GamePlayerHolder extends RecyclerView.ViewHolder {
        TextView tvTeam, tvScore, tvLevel, tvDesc1, tvDesc2, tvPosition, tvName, tvYear;
        ConstraintLayout cl;

        public GamePlayerHolder(@NonNull View itemView) {
            super(itemView);
            tvTeam = itemView.findViewById(R.id.tv_team);
            tvScore = itemView.findViewById(R.id.tv_score);
            tvLevel = itemView.findViewById(R.id.tv_level);
            tvDesc1 = itemView.findViewById(R.id.tv_desc1);
            tvDesc2 = itemView.findViewById(R.id.tv_desc2);
            tvPosition = itemView.findViewById(R.id.tv_position);
            tvName = itemView.findViewById(R.id.tv_name);
            tvYear = itemView.findViewById(R.id.tv_year);
            cl = itemView.findViewById(R.id.cl);
        }
    }
}
